package com.store.bookstore_backend.web.controller;


import com.store.bookstore_backend.domain.Book;
import com.store.bookstore_backend.dto.APIResponse;
import com.store.bookstore_backend.mapper.BookMapper;
import com.store.bookstore_backend.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    BookMapper bookMapper;
    @Autowired
    BookService bookService;

    @GetMapping("/showBooks")
    public APIResponse<List<Book>> showBooks() {
        return APIResponse.success(bookService.getAllBooks());
    }

    @GetMapping("/{id}")
    public APIResponse<Book> showBook(@PathVariable int id) {
        return APIResponse.success(bookService.showBook(id));
    }

    //图书信息检索根据分类
    @GetMapping("/findByCategory/{id}")
    public APIResponse<List<Book>> findByCategory(@PathVariable int id) {
        return APIResponse.success(bookService.findByCategory(id));
    }

    //根据书名/作者/出版社检索图书
    @GetMapping("/searchBook")
    public APIResponse<List<Book>> findByQuery(String query) {
        return APIResponse.success(bookService.findByQuery(query));
    }

}
